{extend name="common:base-user" /}
{block name="title"}留言反馈 - 天佑二手货{/block}
{block name="page"}goods{/block}


{block name="main"}
<div class="am-container am-margin-top-sm">
        <h3>添加留言</h3>
        <hr>
        <form class="am-form">

            <div class="am-form-group am-margin-top">
                <input type="text" name="title" placeholder="标题(留空默认取内容前15个字)">
            </div>
            <div class="am-form-group am-margin-top">
                <textarea id="editor" placeholder="内容(必选)" name="content" rows="3" required></textarea>
            </div>
            <br>
            <div class="am-form-group am-form-icon am-form-feedback am-g-collapse am-cf">
                <label for="captcha" class="am-u-sm-3 am-form-label">
                    <div id="captcha-img" title="刷新验证码"><img src="{:captcha_src()}" alt="captcha" /></div>
                </label>
                <div class="am-u-sm-3">
                    <input type="text" name="captcha" id="captcha" class="am-form-field" placeholder="请输入验证码">
                    <!-- <span class="am-icon-warning"></span> -->
                </div>
            </div>
            <div class="am-cf am-margin-top">
                <button id="form-submit" class="am-btn am-btn-primary" type="submit">确认</button>
            </div>
        </form>
</div>
{/block}

{block name="js"}
<script type="text/javascript">
    $('.am-form').submit(function(event) {
            event.preventDefault();
            $.ajax({
                url: "{:url('feedback/add')}",
                type: 'POST',
                data: $('.am-form').serialize(),
                success: function(data) {
                    console.log(data);
                    $alert = $('#am-alert');
                    $alert.find('.content').text(data.msg);
                    $alert.modal('open');
                    if(data.code) {
                        setTimeout(function() {
                            location.href = data.url;
                        }, data.wait * 1000);
                    } else {
                        $('#captcha-img').click();
                    }
                }
            })
        });

</script>
{/block}
